'use strict';

angular.module('hanxinBroker').directive('checkIsPassword', function twIsWord() {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function (scope, element, attrs, ngModel) {
      ngModel.$parsers.push(function (value) {
        if (_.isUndefined(value)) {
          return undefined;
        }

        // 只能由数字、字母组成，并且至少包含数字和字母
        var isPassword = !(/^[0-9]+$/.test(value));

        ngModel.$setValidity('password', isPassword);

        return isPassword ? value : undefined;
      });
    }
  };
});
